﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Tenmah.BusinessLogic.BusinessEntities;
using Tenmah.DataAccess;

namespace Tenmah.BusinessLogic
{
    public class FacultyModel:Faculty, IDataEntity
    {
        bool? isAddingAllowed;

        public bool IsAddingAllowed
        {
            get
            {
                if(isAddingAllowed == null)
                {
                    throw new Exception("Method need realization");
                }
                return isAddingAllowed??false;
            }
        }

        public void Add()
        {
            if (IsAddingAllowed)
            {
                FacultyDBAccessor.AddFaculty(this);
            }
            else
                throw new Exception("Adding of a new faculty is not allowed.");
        }

        bool? isEditingAllowed;

        public bool IsEditingAllowed
        {
            get
            {
                if (isEditingAllowed == null)
                {
                    throw new Exception("Method need realization");
                }
                return isEditingAllowed ?? false;
            }
        }

        public void Edit()
        {
            if (IsEditingAllowed)
            {
                FacultyDBAccessor.EditFaculty(this);
            }
            else
                throw new Exception("Editing of this faculty is not allowed");
        }

        bool? isDeletingAllowed;

        public bool IsDeletingAllowed
        {
            get
            {
                if (isDeletingAllowed == null)
                {
                    throw new Exception("Method need realization");
                }
                return isDeletingAllowed ?? false;
            }
        }

        public void Delete()
        {
            if (IsDeletingAllowed)
            {
                FacultyDBAccessor.DeleteFaculty(this.id??0);
            }
            else
                throw new Exception("Deleting of this faculty is not allowed");
        }

        public void Reload()
        {
            this.Copy(FacultyDBAccessor.GetFaculty(id??0));
        }

        public void Load(int id)
        {
            this.id = id;
            Reload();
        }

        public FacultyModel(int id)
        {
            this.Copy(FacultyDBAccessor.GetFaculty(id));
        }

        public FacultyModel(string title, string desc)
            : base(null, title, desc)
        {
        }
    }
}
